﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace BusDiary
{
    public partial class frmCatalog : Form
    {
        public frmCatalog()
        {
            InitializeComponent();
        }

        private void btnLoad_Click(object sender, EventArgs e)
        {
            var catalog = BusDiary.Access.DiaryCatalog.Instance.GetAll();
            //this.gridCatalog.DataSource = catalog;
            this.bindingSource1.DataSource = catalog;
        }

        /// <summary>
        /// 目录的基本定义
        /// </summary>
        public class CatalogDefent
        {
            public string Name
            {
                get;
                set;
            }

            public int ID
            {
                get;
                set;
            }

            static public List<CatalogDefent> Lists
            {
                get
                {
                    var ret= new List<CatalogDefent>();
                    ret.Add(new CatalogDefent() { ID=1, Name="上班" });
                    ret.Add(new CatalogDefent() { ID = 2, Name = "下班" });
                    ret.Add(new CatalogDefent() { ID = 3, Name = "临睡" });
                    return ret;
                }
            }
        }

        private void frmCatalog_Load(object sender, EventArgs e)
        {
            catalogDefentBindingSource.DataSource = CatalogDefent.Lists;
            btnLoad_Click(null, null);
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            List<Entity.DiaryCatalog> catalog = this.bindingSource1.DataSource as List<Entity.DiaryCatalog>;
            catalog.ForEach(o => {
                Access.DiaryCatalog.Instance.Update(o);
            });
        }
    }
}
